/*
 * @Author: your name
 * @Date: 2021-10-06 11:40:54
 * @LastEditTime: 2021-10-06 12:13:13
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\1.2排序\P5143\main.cpp
 */
#include<iostream>
using namespace std;
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<iomanip>

const int MAX_POINT_NUM = 50010;

typedef struct Point{
  int x;
  int y;
  int z;
}point;
//检测空指针
void judgeMemory(void* p);
//排序 z 升序 快排
void ZSort(point** p,int l,int r);
//计算距离
double getDistance(point p1,point p2);

int main(){
  //输入点数
  int pointNum;
  cin >> pointNum;
  //创建点指针数组
  point** p = (point**)malloc(sizeof(point*)*(pointNum+2));
  judgeMemory(p);
  //为每个指针分配空间
  for(int i=1; i<=pointNum; i++){
    p[i] = (Point*)malloc(sizeof(Point));
    judgeMemory(p[i]);
    cin >> p[i]->x >> p[i]->y >> p[i]->z;
  }
  //排序
  ZSort(p,1,pointNum);
  // cout << "----------------" << endl;
  // for(int i=1; i<=pointNum; i++){
  //   cout << p[i]->x << " " << p[i]->y << " " << p[i]->z << endl;
  // }
  // cout << "dis:" << getDistance(*p[1],*p[2]) << endl;
  //计算总距离
  double sumDis = 0;
  for(int i=1; i<pointNum; i++){
    sumDis += getDistance(*p[i],*p[i+1]);
  }
  // cout << "sumDistance:" << sumDis << endl;
  cout << fixed << setprecision(3) << sumDis << endl;
  //释放空间
  p[0] = NULL;
  for(int i=1; i<=pointNum; i++){
    if(p[i]){
      free(p[i]);
      p[i] = NULL;
    }
  }
  if(p){
    free(p);
    p = NULL;
  }
  return 0;
}
void judgeMemory(void* p)
{
  if(!p){
    cout << "no memory" << endl;
    exit(-1);
  }
}

void ZSort(point** p,int l,int r)
{
  if(l < r){
    //随机化枢轴
    srand(time(NULL));
    int randIndex = rand()%(r-l+1)+l;
    point* pivot = p[randIndex];
    p[randIndex] = p[l];
    p[l] = pivot;
    //快排
    int low = l;
    int high = r;
    while(low < high){
      while((low < high) && (pivot->z < p[high]->z)){
        high--;
      }
      if(low < high){
        p[low++] = p[high];
      }
      while((low < high) && (pivot->z > p[low]->z)){
        low++;
      }
      if(low < high){
        p[high--] = p[low];
      }
    }
    p[low] = pivot;
    ZSort(p,l,low-1);
    ZSort(p,low+1,r);
  }
}

double getDistance(point p1,point p2)
{
  return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}